package agent.ccs
import agent.AgentCalculus
import agent.AgentParser
import cwb.CWBParseException
import agent.Agent
import agent.Action

object CCSCalculus extends AgentCalculus {
  val parser = new CCSParser
  val Tau = new Tau(None)
  val component = CCSComponent
  val agentObject = CCSAgent
  val agentCommand = AgentCommand
  
  /**
   * Given a list of (Symbol, Agent) pairs; stores variable Sym => agent in the global environment.
   * Also verifies that the given symbols are valid agent identifiers.
   * @param symAgList list of (Symbol, Agent) pairs to be linked together
   */
  def bindVarsToAgents(symAgList: List[(Symbol, Agent)]) = {
    // Verify the correctness of the symbols before binding
    def sanityCheck(sym: Symbol) {
      if (!parser.isValidAgentName(sym.name)) {
        throw new CWBParseException("Invalid agent identifier")
      }
    }
    for ((sym, _) <- symAgList) sanityCheck(sym)
    // Assumed to be sane by the time we reach here to use CCS!
    for ((sym, ag: CCSAgent) <- symAgList) {
      CCSComponent.environment.insertBinding(sym, ag)
    }
  }
  
  def makeAgentFromNextSteps(lst: List[(Action, List[Symbol])]) =
    CCSAgent.makeAgentFromNextSteps(lst.asInstanceOf[List[(CCSAction, List[Symbol])]])
}